<template>
	<div class="app-container">
		<el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch"
			label-width="100px">
			<el-form-item label="订单编号" prop="orderNo">
				<el-input v-model="queryParams.orderNo" placeholder="请输入订单编号" clearable
					@keyup.enter.native="handleQuery" />
			</el-form-item>
			<el-form-item label="下单用户" prop="payUser">
				<el-input v-model="queryParams.payUser" placeholder="请输入下单用户" clearable
					@keyup.enter.native="handleQuery" />
			</el-form-item>
			<el-form-item label="服务技师" prop="payTechnicianName">
				<el-input v-model="queryParams.payTechnicianName" placeholder="请输入服务技师" clearable
					@keyup.enter.native="handleQuery" />
			</el-form-item>
			<el-form-item label="下单项目名" prop="payItemName">
				<el-input v-model="queryParams.payItemName" placeholder="请输入下单项目名" clearable
					@keyup.enter.native="handleQuery" />
			</el-form-item>
			<el-form-item label="消费类型" prop="consumptionType">
				<el-select v-model="queryParams.consumptionType" placeholder="请选择消费类型" clearable>
					<el-option v-for="dict in dict.type.consume_type" :key="dict.value" :label="dict.label"
						:value="dict.value" />
				</el-select>
			</el-form-item>
			<el-form-item>
				<el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
				<el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
			</el-form-item>
		</el-form>

		<el-tabs v-model="activeName" type="card" @tab-click="handleClick">
			<el-tab-pane label="业务员佣金记录" name="first">
				<el-table v-loading="loading" :data="salesmanConsumeDetailList">
					<el-table-column label="ID" align="center" prop="id" />
					<el-table-column label="业务员" align="center" prop="salesmanName" />
					<el-table-column label="订单编号" align="center" prop="orderNo" />
					<el-table-column label="下单用户" align="center" prop="payUser" />
					<el-table-column label="服务技师" align="center" prop="payTechnicianName" />
					<el-table-column label="下单项目图" align="center" prop="payItemPicture" width="100">
						<template slot-scope="scope">
							<image-preview :src="scope.row.payItemPicture" :width="50" :height="50" />
						</template>
					</el-table-column>
					<el-table-column label="下单项目名" align="center" prop="payItemName" />
					<el-table-column label="下单数量" align="center" prop="payCount" />
					<el-table-column label="下单时间" align="center" prop="payTime">
						<template slot-scope="scope">
							<span>{{ parseTime(scope.row.payTime) }}</span>
						</template>
					</el-table-column>
					<el-table-column label="订单金额" align="center" prop="payPrice" />
					<el-table-column label="项目金额" align="center" prop="itemPrice" />
					<el-table-column label="分佣金额" align="center" prop="sharePrice" />
					<el-table-column label="消费类型" align="center" prop="consumptionType">
						<template slot-scope="scope">
							<dict-tag :options="dict.type.consume_type" :value="scope.row.consumptionType" />
						</template>
					</el-table-column>
					<el-table-column label="提现金额" align="center" prop="payoutPrice" />
					<el-table-column label="描述" align="center" prop="consumptionDescribe" />
					<el-table-column label="创建时间" align="center" prop="createTime">
						<template slot-scope="scope">
							<span>{{ parseTime(scope.row.createTime) }}</span>
						</template>
					</el-table-column>
				</el-table>
				<pagination v-show="total>0" :total="total" :page.sync="queryParams.pageNum"
					:limit.sync="queryParams.pageSize" @pagination="getList" />
			</el-tab-pane>

			<el-tab-pane label="渠道商佣金记录" name="second">
				<el-table v-loading="loading" :data="channelConsumeDetailList">
					<el-table-column label="ID" align="center" prop="id" />
					<el-table-column label="渠道商" align="center" prop="channelName" />
					<el-table-column label="订单编号" align="center" prop="orderNo" />
					<el-table-column label="下单用户" align="center" prop="payUser" />
					<el-table-column label="服务技师" align="center" prop="payTechnicianName" />
					<el-table-column label="下单项目图" align="center" prop="payItemPicture" width="100">
						<template slot-scope="scope">
							<image-preview :src="scope.row.payItemPicture" :width="50" :height="50" />
						</template>
					</el-table-column>
					<el-table-column label="下单项目名" align="center" prop="payItemName" />
					<el-table-column label="下单数量" align="center" prop="payCount" />
					<el-table-column label="下单时间" align="center" prop="payTime">
						<template slot-scope="scope">
							<span>{{ parseTime(scope.row.payTime) }}</span>
						</template>
					</el-table-column>
					<el-table-column label="订单金额" align="center" prop="payPrice" />
					<el-table-column label="项目金额" align="center" prop="itemPrice" />
					<el-table-column label="分佣金额" align="center" prop="sharePrice" />
					<el-table-column label="消费类型" align="center" prop="consumptionType">
						<template slot-scope="scope">
							<dict-tag :options="dict.type.consume_type" :value="scope.row.consumptionType" />
						</template>
					</el-table-column>
					<el-table-column label="描述" align="center" prop="consumptionDescribe" />
					<el-table-column label="创建时间" align="center" prop="createTime">
						<template slot-scope="scope">
							<span>{{ parseTime(scope.row.createTime) }}</span>
						</template>
					</el-table-column>
				</el-table>

				<pagination v-show="channeTotal>0" :total="channeTotal" :page.sync="queryParams.pageNum"
					:limit.sync="queryParams.pageSize" @pagination="channeList" />
			</el-tab-pane>
			<el-tab-pane label="经纪人佣金记录" name="third">
				<el-table v-loading="loading" :data="brokerConsumeDetailList">
					<el-table-column label="ID" align="center" prop="id" />
					<el-table-column label="经纪人" align="center" prop="brokerName" />
					<el-table-column label="订单编号" align="center" prop="orderNo" />
					<el-table-column label="下单用户" align="center" prop="payUser" />
					<el-table-column label="服务技师" align="center" prop="payTechnicianName" />
					<el-table-column label="下单项目图" align="center" prop="payItemPicture" width="100">
						<template slot-scope="scope">
							<image-preview :src="scope.row.payItemPicture" :width="50" :height="50" />
						</template>
					</el-table-column>
					<el-table-column label="下单项目名" align="center" prop="payItemName" />
					<el-table-column label="下单数量" align="center" prop="payCount" />
					<el-table-column label="下单时间" align="center" prop="payTime">
						<template slot-scope="scope">
							<span>{{ parseTime(scope.row.payTime) }}</span>
						</template>
					</el-table-column>
					<el-table-column label="订单金额" align="center" prop="payPrice" />
					<el-table-column label="项目金额" align="center" prop="itemPrice" />
					<el-table-column label="分佣金额" align="center" prop="sharePrice" />
					<el-table-column label="消费类型" align="center" prop="consumptionType">
						<template slot-scope="scope">
							<dict-tag :options="dict.type.consume_type" :value="scope.row.consumptionType" />
						</template>
					</el-table-column>
					<el-table-column label="描述" align="center" prop="consumptionDescribe" />
					<el-table-column label="创建时间" align="center" prop="createTime">
						<template slot-scope="scope">
							<span>{{ parseTime(scope.row.createTime) }}</span>
						</template>
					</el-table-column>
				</el-table>

				<pagination v-show="brokerTotal>0" :total="brokerTotal" :page.sync="queryParams.pageNum"
					:limit.sync="queryParams.pageSize" @pagination="brokerList" />
			</el-tab-pane>
		</el-tabs>





		<!-- 添加或修改业务员佣金记录对话框 -->
		<el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
			<el-form ref="form" :model="form" :rules="rules" label-width="80px">
			</el-form>
			<div slot="footer" class="dialog-footer">
				<el-button type="primary" @click="submitForm">确 定</el-button>
				<el-button @click="cancel">取 消</el-button>
			</div>
		</el-dialog>
	</div>
</template>

<script>
	import {
		listSalesmanConsumeDetail,
		getSalesmanConsumeDetail,
		delSalesmanConsumeDetail,
		addSalesmanConsumeDetail,
		updateSalesmanConsumeDetail
	} from "@/api/salesmanConsumeDetail/salesmanConsumeDetail";
	import {
		listChannelConsumeDetail
	} from "@/api/channelConsumeDetail/channelConsumeDetail";
	import {
		listBrokerConsumeDetail
	} from "@/api/brokerConsumeDetail/brokerConsumeDetail";

	export default {
		name: "SalesmanConsumeDetail",
		dicts: ['consume_type'],
		data() {
			return {
				activeName: 'first',
				// 遮罩层
				loading: true,
				// 选中数组
				ids: [],
				// 非单个禁用
				single: true,
				// 非多个禁用
				multiple: true,
				// 显示搜索条件
				showSearch: true,
				// 总条数
				total: 0,
				// 业务员佣金记录表格数据
				salesmanConsumeDetailList: [],
				channeTotal: 0,
				// 渠道商佣金记录表格数据
				channelConsumeDetailList: [],
				brokerTotal: 0,
				// 经纪人佣金记录表格数据
				brokerConsumeDetailList: [],
				// 弹出层标题
				title: "",
				// 是否显示弹出层
				open: false,
				// 查询参数
				queryParams: {
					pageNum: 1,
					pageSize: 10,
					orderNo: null,
					payUser: null,
					payTechnicianName: null,
					payItemPicture: null,
					payItemName: null,
					consumptionType: null,
				},
				// 表单参数
				form: {},
				// 表单校验
				rules: {}
			};
		},
		created() {
			if (this.activeName == 'first') this.getList()
		},
		methods: {
			/** 查询业务员佣金记录列表 */
			getList() {
				this.loading = true;
				listSalesmanConsumeDetail(this.queryParams).then(response => {
					this.salesmanConsumeDetailList = response.rows;
					this.total = response.total;
					this.loading = false;
				});
			},
			/** 查询渠道商佣金记录列表 */
			channeList() {
				this.loading = true;
				listChannelConsumeDetail(this.queryParams).then(response => {
					this.channelConsumeDetailList = response.rows;
					this.channeTotal = response.total;
					this.loading = false;
				});
			},
			/** 查询经纪人佣金记录列表 */
			brokerList() {
				this.loading = true;
				listBrokerConsumeDetail(this.queryParams).then(response => {
					this.brokerConsumeDetailList = response.rows;
					this.brokerTotal = response.total;
					this.loading = false;
				});
			},
			// 取消按钮
			cancel() {
				this.open = false;
				this.reset();
			},
			// 表单重置
			reset() {
				this.form = {
					id: null,
					salesmanId: null,
					orderNo: null,
					payUser: null,
					payTechnicianName: null,
					payItemPicture: null,
					payItemName: null,
					payCount: null,
					payTime: null,
					payPrice: null,
					itemPrice: null,
					sharePrice: null,
					salesmanPayoutId: null,
					consumptionType: null,
					payoutPrice: null,
					consumptionDescribe: null,
					isDelete: null,
					createTime: null,
					updateTime: null
				};
				this.resetForm("form");
			},
			querReset() {
				this.queryParams = {
					pageNum: 1,
					pageSize: 10,
					orderNo: null,
					payUser: null,
					payTechnicianName: null,
					payItemPicture: null,
					payItemName: null,
					consumptionType: null,
				}
			},
			/** 搜索按钮操作 */
			handleQuery() {
				this.queryParams.pageNum = 1;
				if (this.activeName == 'first') this.getList()
				if (this.activeName == 'second') this.channeList()
				if (this.activeName == 'third') this.brokerList()
			},
			/** 重置按钮操作 */
			resetQuery() {
				this.resetForm("queryForm");
				this.handleQuery();
			},
			// 多选框选中数据
			handleSelectionChange(selection) {
				this.ids = selection.map(item => item.id)
				this.single = selection.length !== 1
				this.multiple = !selection.length
			},
			/** 新增按钮操作 */
			handleAdd() {
				this.reset();
				this.open = true;
				this.title = "添加业务员佣金记录";
			},
			/** 修改按钮操作 */
			handleUpdate(row) {
				this.reset();
				const id = row.id || this.ids
				getSalesmanConsumeDetail(id).then(response => {
					this.form = response.data;
					this.open = true;
					this.title = "修改业务员佣金记录";
				});
			},
			/** 提交按钮 */
			submitForm() {
				this.$refs["form"].validate(valid => {
					if (valid) {
						if (this.form.id != null) {
							updateSalesmanConsumeDetail(this.form).then(response => {
								this.$modal.msgSuccess("修改成功");
								this.open = false;
								this.getList();
							});
						} else {
							addSalesmanConsumeDetail(this.form).then(response => {
								this.$modal.msgSuccess("新增成功");
								this.open = false;
								this.getList();
							});
						}
					}
				});
			},
			// 标签点击
			handleClick(tab, event) {
				this.activeName = tab.name
				this.querReset()
				if (this.activeName == 'first') this.getList()
				if (this.activeName == 'second') this.channeList()
				if (this.activeName == 'third') this.brokerList()
			},
			/** 删除按钮操作 */
			handleDelete(row) {
				const ids = row.id || this.ids;
				this.$modal.confirm('是否确认删除业务员佣金记录编号为"' + ids + '"的数据项？').then(function() {
					return delSalesmanConsumeDetail(ids);
				}).then(() => {
					this.getList();
					this.$modal.msgSuccess("删除成功");
				}).catch(() => {});
			},
			/** 导出按钮操作 */
			handleExport() {
				this.download('salesmanConsumeDetail/salesmanConsumeDetail/export', {
					...this.queryParams
				}, `salesmanConsumeDetail_${new Date().getTime()}.xlsx`)
			}
		}
	};
</script>